package aspect;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import service.WorkServic;
import service.impl.WorkServiceImpl;

public class LogAspect implements InvocationHandler{
	private Object target;
	private Log log=LogFactory.getLog(LogAspect.class);
	
	public void setTarget(Object target) {
		this.target = target;
	}
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		log.info("before......"+method.getName());
		Object o=method.invoke(target, args);
		return o;
	}
	
	public static void main(String[] args) {
//		LogAspect logAspect=new LogAspect();
//		WorkServic ws=new WorkServiceImpl();
//		logAspect.setTarget(ws);
//		
//		Class[] clazzes=new Class[] {WorkServic.class};
//		WorkServic wsProxy=(WorkServic) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), clazzes, logAspect);
//		String rs=wsProxy.work("john");
//		System.out.println(rs);
	}

}
